package io.summer.gadget.channel.core;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author ml
 */
@RestController
@RequestMapping
@ConditionalOnBean(MessageDispatcher.class)
public final class Messenger {
    @Autowired
    private MessageDispatcher messageDispatcher;

    @PostMapping(ChannelConst.RECEIVER)
    public byte[] receive(@RequestBody ChannelRequest data) {
        return messageDispatcher.dispatch(data);
    }

    @PostMapping(ChannelConst.RECEIVER_ASYNC)
    public byte[] receiveAsync(@RequestBody ChannelRequest data) {
        return messageDispatcher.dispatchAsync(data);
    }
}
